package com.patrol.quartz;

import com.patrol.service.WorkerService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LCPointExportJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(LCPointExportJob.class);

    @Autowired
    private WorkerService workerService;

    @Override
    public void execute(JobExecutionContext context) {
        logger.info("[导出巡更人员任务点漏查数量任务开始]");
        this.lcPointExport();
        logger.info("[导出巡更人员任务点漏查数量任务结束]");
    }

    private void lcPointExport() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String time = df.format(new Date());

        int rwNum = workerService.selectRWNum();
        int rwlcNum = workerService.selectRWLCNum();

        //高风险点位数量
        int hfxnum = workerService.selectHfxNum();
        //中风险点位数量
        int zfxnum = workerService.selectZfxNum();
        //低风险点位数量
        int dfxnum = workerService.selectDfxNum();

        Integer id = workerService.selectRWReport(time);
        if (null == id){
            workerService.addRWTJ(rwNum,rwlcNum,time,hfxnum,zfxnum,dfxnum);
        }else {
            workerService.updateRWTJ(id,rwlcNum,hfxnum,zfxnum,dfxnum);
        }
    }
}
